package com.itheima.service.impl.member;

import com.itheima.dao.member.MemberDao;
import com.itheima.service.member.MemberService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 林金洋
 * @since 2021/11/4 16:06
 */
@Service(interfaceClass = MemberService.class)
@Transactional(readOnly = true)
public class MemberServiceImpl implements MemberService{
    @Autowired
    private MemberDao memberDao;

    /**
     * 根据月份查询会员数量
     * @param months 传入对象集合
     * @return 返回数据集合
     */
    @Override
    public List<Integer> findMemberCountBeforeMonth(List<String> months) {
        List<Integer> memberCount = new ArrayList<>();
        for (String month : months){
            String date = month + "-31";
            Integer count = memberDao.findMemberCountBeforeMonth(date);
            memberCount.add(count);
        }
        return memberCount;
    }
}
